<div id="app">
  <div class="p2 flex items-center">
    <a href="/client/home" class="weui-btn weui-btn_mini weui-btn_default"> 返回 </a>
    <div style="flex: 1"></div>
    <!-- <div >全部</div>
    <div>红包</div>
    <div>商品</div>
    <div>兑换码</div> -->

    <!-- <div class="weui-btn weui-btn_mini weui-btn_primary" @click="exportCSV">导出下载</div> -->
  </div>

  <div>
    <div class="weui-cells__title">兑换记录</div>
    <div class="weui-cells">
      <div class="weui-cell" v-for="pointOrder in pointOrders">
        <div class="weui-cell__hd font-13 bold flex items-center" style="width: 150px">
          <img style="width: 30px; height: 30px" class="circle" v-bind:src="pointOrder.item.photo" />
          {{pointOrder.item.name}} {{pointOrder.item.type =='red'? pointOrder.item.red_money + '元' : ''}}

          {{pointOrder.item.type =='code' ? pointOrder.item.code :''}}
        </div>
        <div class="weui-cell__bd px2 font-12">
          <div class="flex items-center">
            <!-- <img style="width: 20px; height: 20px" class="circle" v-bind:src="pointOrder.userinfo.headimgurl" /> -->
            <a class="underline blue"
              v-bind:href="'/client/user/'+pointOrder.contactid">{{pointOrder.userinfo.nickname}}</a>
          </div>
          <div class="gray">{{pointOrder.createTime}}</div>
          <div class="gray" v-if="pointOrder.addressInfo">
            {{pointOrder.addressInfo.address + ' ' + pointOrder.addressInfo.name + ' ' + pointOrder.addressInfo.phone}}
          </div>
          <div class="gray" v-if="pointOrder.checked">已核销 核销时间 {{pointOrder.checkTime| datetime}}</div>
          <div @click="checkOrder(pointOrder)" class="underline blue"
            v-if="(pointOrder.item.type =='code' || pointOrder.item.type =='daodian' || pointOrder.item.getway =='qrcode') && !pointOrder.checked">
            手动核销
          </div>
        </div>
        <div class="weui-cell__ft">-{{pointOrder.point}}</div>
      </div>
    </div>

    <div v-if="pointOrders.length==0" class="gray my2 center">
      <img src="/img/empty.png" style="width: 150px" />
      <div class="font-12 bold">没有更多数据了</div>
    </div>
  </div>

  <!-- <div class="p2 font-12 gray center">到底了~</div> -->
</div>

<script>
  new Vue({
    el: "#app",
    data: {
      pointOrders: [],
    },

    created: function () {
      this.refresh();
    },
    filters: {
      datetime: function (time) {
        return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
      },
    },
    methods: {
      exportCSV: function () {
        weui.alert("链接已复制, 请到发送到电脑打开");
      },
      refresh: function () {
        let that = this;
        let loading = weui.loading();
        axios.get("/client/getPointOrders").then((res) => {
          loading.hide();
          let { pointOrders } = res.data;
          console.log(pointOrders);
          that.pointOrders = pointOrders;
        });
      },
      checkOrder: function (order) {
        let that = this;
        if (confirm("核销后无法再次核销, 请联系相关人员确认是否手动核销")) {
          axios
            .post("/user/client/<%=client._id%>/checkorder", {
              orderid: order._id,
            })
            .then(function (res) {
              if (!res.data.status) {
                weui.topTips(res.data.msg);
              } else {
                weui.toast("核销成功");
                that.getPointOrders();
              }

              location.reload()
            });
        }
      },
    },
  });
</script>